let baseURL = "";
if (process.env.NODE_ENV === 'development') {
	// #ifdef H5
		// #ifdef H5-101
			baseURL = 'http://192.168.1.101/shopapi'
		// #endif
		// #ifdef H5-239
			baseURL = 'http://192.168.1.239/shopapi'
		// #endif
		// #ifdef H5-WX
			baseURL = 'https://weixin.cciinet.com/shopapi'
		// #endif
		// #ifdef H5-PROD
			baseURL = 'https://m.cciinet.com/shopapi'
		// #endif
	// #endif
	// #ifdef !H5
	baseURL = 'http://192.168.1.239/shopapi'
	// #endif
} else {
	// #ifdef H5
		// #ifdef H5-101
			baseURL = 'http://192.168.1.101/shopapi'
		// #endif
		// #ifdef H5-239
			baseURL = 'http://192.168.1.239/shopapi'
		// #endif
		// #ifdef H5-WX
			baseURL = 'https://weixin.cciinet.com/shopapi'
		// #endif
		// #ifdef H5-PROD
			baseURL = 'https://m.cciinet.com/shopapi'
		// #endif
	// #endif
	// #ifdef !H5
	baseURL = 'https://m.cciinet.com/shopapi'
	// #endif
}

/**
 * get方法，对应get请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function GET(url, params,loading=false,title="加载中...") {
	if(loading) {
		uni.showLoading({
			title:title
		})
	}
	return new Promise((resolve, reject) => {
		uni.request({
				url: baseURL + url,
				data: params,
				method: 'GET'
			})
			.then(data => {
				var [error, res] = data
				if (res.data.data && res.data.data.code && res.data.data.code == 1000) {
					uni.showToast({
						title: '内容存在敏感词',
						icon: 'none'
					});
					return
				}
				resolve(res.data);
				if(loading) {
					 uni.hideLoading()
				}
			})
			.catch(err => {
				reject(err)
			})
	});
}
/**
 * post方法，对应post请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function POST(url, params,loading=false,title="加载中...") {
	if(loading) {
		uni.showLoading({
			title:title
		})
	}
	return new Promise((resolve, reject) => {
		uni.request({
				url: baseURL + url,
				data: params,
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				}
			})
			.then(data => {
				var [error, res] = data
				if (res.data.data && res.data.data.code && res.data.data.code == 1000) {
					uni.showToast({
						title: '内容存在敏感词',
						icon: 'none'
					});
					return
				}
				resolve(res.data);
				if(loading) {
					 uni.hideLoading()
				}
			})
			.catch(err => {
				reject(err)
			})
	});
}

export function POST_JSON(url, params,loading=false,title="加载中...") {
	if(loading) {
		uni.showLoading({
			title:title
		})
	}
	return new Promise((resolve, reject) => {
		uni.request({
				url: baseURL + url,
				data: params,
				method: 'POST'
			})
			.then(data => {
				var [error, res] = data
				if (res.data.data && res.data.data.code && res.data.data.code == 1000) {
					uni.showToast({
						title: '内容存在敏感词',
						icon: 'none'
					});
					return
				}
				resolve(res.data);
				if(loading) {
					 uni.hideLoading()
				}
			})
			.catch(err => {
				reject(err)
			})
	});
}
/**
 * post方法，对应post请求, form-data
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function FILE(url, params) {
	let data = {
		url: baseURL + url, //仅为示例，非真实的接口地址
		filePath: params.file,
		method: 'POST',
		name: 'file',
		formData: params.formData
	}
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title:"正在上传..."
		})
		uni.uploadFile({
				url: baseURL + url, //仅为示例，非真实的接口地址
				filePath: params.file,
				method: 'POST',
				name: 'file',
				formData: params.formData,
			})
			.then(data => {
				var [error, res] = data
				console.log(res)
				let obj = JSON.parse(res.data)
				if (obj.data.code && obj.data.code == 1000) {
					uni.showToast({
						title: '内容存在敏感词',
						icon: 'none'
					});
					return
				}
				 uni.hideLoading()
				resolve(res.data);
			})
			.catch(err => {
				reject(err)
			})
	});
}
